﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace SnakeInitial
{
    public partial class SnakeBoard : Form
    {
        int player = 1, PlayerTurnCount = 0, formclosingcount = 0,pictureboxthreadcount=0;
        int grid1 = 0, grid2 = 0, grid3 = 0, chance1 = 0, go = 2, temp,threadcount=0,playernamecount=0,GroupBoxPlayerNameCount=0;
        string Player1Name, Player2Name, Player3Name;
        public SnakeBoard()
        {
            InitializeComponent();
        }
        public SnakeBoard(bool values)
        {
            InitializeComponent();
            groupBox2.Visible = values;
            
        }
        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        public void threadtrycoin()
        {
            ThreadStart tscoin = new ThreadStart(cointry);
            Thread thcoin = new Thread(tscoin);

            thcoin.Start();
        }
        public void cointry()
        {
            Thread.Sleep(500);
            PbPlayer1Coin.Invoke(new MethodInvoker(() => PbPlayer1Coin.Visible=true));
            PbPlayer2Coin.Invoke(new MethodInvoker(() => PbPlayer2Coin.Visible = true));
            PbPlayer3Coin.Invoke(new MethodInvoker(() => PbPlayer3Coin.Visible = true));
        }
        public void threadtry(int startorstop)
        {
            ThreadStart ts = new ThreadStart(work);
            Thread th = new Thread(ts);
            if (startorstop == 0)
                th.Start();
            else
                th.Abort();
        }
        public void work()
        {
            if (pictureboxthreadcount == 0)
            {
                string front = "Luck is believing you're lucky.";
                string front2 = "Tennessee Williams(American Poet)";
                for (int j = 0; j < front.Length; j++)
                {
                    Thread.Sleep(120);
                    LblMessage.Invoke(new MethodInvoker(() => lblfront.Text+=Convert.ToString(front[j])));
                }
                LblMessage.Invoke(new MethodInvoker(() => lblfront2.Text += Convert.ToString(front2)));
                Thread.Sleep(7000);
                LblMessage.Invoke(new MethodInvoker(() => lblfront.Visible = false));
                LblMessage.Invoke(new MethodInvoker(() => lblfront2.Visible = false));
                LblMessage.Invoke(new MethodInvoker(() => pictureBox7.Visible = false));
                pictureboxthreadcount = 1;
            }
            label:
            string s = "                                                          Welcome to the Snake Board PC, If your are a lucky person you will win on your sixth roll of Dice.";
            string b = null;
            int length,i;
            length = s.Length;
            if (LblMessage.InvokeRequired)
            {
                LblMessage.Invoke(new MethodInvoker(() => LblMessage.Text = Convert.ToString(s)));
                for (i = 0; i < length; i++)
                {
                    for(int j=1;j<s.Length;j++)
                        b += s[j];
                    Thread.Sleep(120);
                    LblMessage.Invoke(new MethodInvoker(() => LblMessage.Text = Convert.ToString(b)));
                    s = b;
                    b = null;
                }
                
             }
            goto label;
        }
        public void PlayerName(bool lp1, bool tp1, bool lp2, bool tp2, bool lp3, bool tp3,bool bt)
        {
            LblPlayer1Name.Visible = lp1;
            LblPlayer2Name.Visible = lp2;
            LblPlayer3Name.Visible = lp3;
            TbPlayer1Name.Visible = tp1;
            TbPlayer2Name.Visible = tp2;
            TbPlayer3Name.Visible = tp3;
            BtPlayerNameOk.Visible = bt;
        }
        public void Playertick(bool pvc, bool p2, bool p3)
        {
            ObjPlayerVsComputer.Checked = pvc;
            ObjPlayer2.Checked = p2;
            ObjPlayer3.Checked = p3;
        }
        public void GroupBoxPlayerName()
        {
            if (GroupBoxPlayerNameCount == 0)
            {
                comboBox1.Items.Add("Against Computer");
                comboBox1.Items.Add("Against Player");
                comboBox1.Items.Add("Against Multiple Player");
                GroupBoxPlayerNameCount = 1;
            }
        }
        public void PlayerCoinLocation(int gp,int plyr)
        {
            int[] gx = new int[] { 0, 30, 89, 148, 204, 270, 323, 382, 438, 499, 560};
            int[] gy = new int[]  { 593, 532, 476, 418, 358, 299, 243, 183, 125, 65 };
            int count = 1,playercoinlocationcount=0,m=0;
            for (int j = 0; j < 10; j++)
            {
                if (playercoinlocationcount == 0)
                {
                    for (int i = 1; i <= 10; i++)
                    {
                        if (count == gp)
                        {
                            if ((grid1 == grid2 || grid1 == grid3 || grid2 == grid3))
                                m = 30;
                            if (plyr == 0)
                            {
                                PbPlayer1Coin.Visible = false;
                                PbPlayer1Coin.Location = new Point(gx[i]+m, gy[j]-m);
                            }
                            else if (plyr == 1)
                            {
                                PbPlayer2Coin.Visible = false;
                                PbPlayer2Coin.Location = new Point(gx[i]+m, gy[j]);
                            }
                            else if (plyr == 2)
                            {
                                PbPlayer3Coin.Visible = false;
                                PbPlayer3Coin.Location = new Point(gx[i], gy[j]-m);
                            }
                            threadtrycoin();                            
                        }
                        count++;
                    }
                    playercoinlocationcount = 1;
                }
                else if (playercoinlocationcount == 1)
                {
                    for (int i = 10; i >= 1; i--)
                    {
                         if (count == gp)
                         {
                             if (grid1 == grid2 || grid1 == grid3 || grid2 == grid3)
                                 m = 30;
                             if (plyr == 0)
                             {
                                 PbPlayer1Coin.Visible = false;
                                 PbPlayer1Coin.Location = new Point(gx[i]+m, gy[j]-m);
                             }
                             else if (plyr == 1)
                             {
                                 PbPlayer2Coin.Visible = false;
                                 PbPlayer2Coin.Location = new Point(gx[i]+m, gy[j]);
                             }
                             else if (plyr == 2)
                             {
                                 PbPlayer3Coin.Visible = false;
                                 PbPlayer3Coin.Location = new Point(gx[i], gy[j]-m);
                             }
                             threadtrycoin();
                        }
                        count++;
                    }
                    playercoinlocationcount = 0;                    
                }
            }
        }
        public void SnakeBoard_Load(object sender, EventArgs e)
        {
            pictureBox7.BringToFront();
            lblfront.BringToFront();
            lblfront2.BringToFront();
            if (playernamecount == 0)
            {
                GroupBoxPlayerName();
                PlayerName(false, false, false, false, false, false,false);
                groupBox2.Location = new Point(615, 70);
            }
            PbPlayer1Coin.Location = new Point(0, 593);
            PbPlayer2Coin.Location = new Point(0, 561);
            PbPlayer3Coin.Location = new Point(0, 532);
           if(player!=3)
                Pblogo.Visible = true;
           Pblogo.Location = new Point(620, 70);
           if (threadcount == 0)
           {
               threadtry(0);
               threadcount = 1;
           }
          // Pbtrail.BringToFront();
           TbDice.Clear();
           grid1 = 0; grid2 = 0; grid3 = 0;
           GridPosition(0,0,0);
           SerpantsLeft(0,0,0);
           LaddersLeft(0, 0, 0);
           if (player == 3)
               GbPlayer3.Visible = true;
           else
               GbPlayer3.Visible = false;
           GbPlayer1.ForeColor = Color.Green;
           GbPlayer1.Text = Player1Name;
           GbPlayer2.ForeColor = Color.Navy;
           if (player == 2)
               GbPlayer2.Text = Player2Name;
           else if (player == 3)
           {
               GbPlayer3.Text = Player3Name;
               GbPlayer2.Text = Player2Name;
               PbPlayer3.Visible = false;
           }
           else
           GbPlayer2.Text = "Computer";
           if(player==1)
            player = 1;
           PlayerTurnCount = 1;
           LblPlayersTurn.ForeColor = System.Drawing.Color.Green;
           LblPlayersTurn.Text = Player1Name+" Turn";
           Pbplayer2.Visible = false;
           Pbplayer1.Visible = true;
           MsFileNewGame.Enabled = false;           
        }
        private void playerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Playertick(true, false, false);
            player = 1;
            groupBox2.Visible = true;
            comboBox1.Text = "Against Computer";
            BtPlayAgainstWhom_Click(null, null);
            SnakeBoard_Load(null, null);
        }
        private void playerToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Playertick(false, true, false);
            GbPlayer3.Visible = false;
            player = 2;
            groupBox2.Visible = true;
            comboBox1.Text = "Against Player";
            BtPlayAgainstWhom_Click(null, null);
            SnakeBoard_Load(null, null);
        }
        private void ObjPlayer3_Click(object sender, EventArgs e)
        {
            GbPlayer3.Visible = true;
            Pblogo.Visible = false;
            GbPlayer3.ForeColor = Color.Purple;
            Playertick(false, false, true);
            groupBox2.Visible = true;
            comboBox1.Text = "Against Multiple Player";
            TbDice.Clear();
            player = 3;
            BtPlayAgainstWhom_Click(null, null);
            SnakeBoard_Load(null,null);
        }
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formclosingcount = 1;
            string MbInstructuionQuit = "Do you want to Quit this Game";
            string Mbquit = "Quit Window";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result = MessageBox.Show(MbInstructuionQuit, Mbquit, buttons);
            if (result == DialogResult.Yes)
            {
                threadtry(1);
                Environment.Exit(0);
            }
            else
            {
                //threadtry(0);
                formclosingcount = 0;
            }
        }
        private void MScriptHelpAboutSBPC_Click(object sender, EventArgs e)
        {
            string MbInstructionsDevelopers = "Game Name : Snake Board PC \nVersion          : 1.0\nDeveloper     : Gowtham Sugumar \n\t      (Student From NIIT Nungambakkam,INDIA)\nSource of Motivation : Mr.Kunal Subhankar";
            string MbDevelopers="About Snake Board PC game";
            MessageBox.Show(MbInstructionsDevelopers,MbDevelopers);
        }
        private void groupBox1_Enter(object sender, EventArgs e)
        {
        }
        private void BtDice_Click(object sender, EventArgs e)
        {
            MsFileNewGame.Enabled = true;
            if (player == 1)
            {
                if (PlayerTurnCount == 0)
                {
                    PlayerTurnCount = 1;
                    Pbplayer2.Visible = false;
                    Pbplayer1.Visible = true;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Green;
                    LblPlayersTurn.Text = Player1Name+" Turn";
                    BtDice.BackColor = System.Drawing.Color.Maroon;
                    BtDice.ForeColor = System.Drawing.Color.LightSalmon;
                    TbDice.ForeColor = System.Drawing.Color.Navy;
                    BtDice.Enabled = true;                    
                }
                else
                {
                    PlayerTurnCount = 0;
                    Pbplayer1.Visible = false;
                    Pbplayer2.Visible = true;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Navy;
                    LblPlayersTurn.Text = "Computer Turn";
                    BtDice.BackColor = System.Drawing.Color.Gray;
                    BtDice.ForeColor = System.Drawing.Color.Gray;
                    BtDice.Enabled = false;
                    go = 0;
                    TbDice.ForeColor = System.Drawing.Color.Green;
                    PbPlayer3Coin.BackColor = Color.Transparent;
                   // GraphicsPath gp = new GraphicsPath();
                   // gp.AddEllipse(Pbtrail.DisplayRectangle);
                    //Pbtrail.Region = new Region(gp);
                    //pictureBox6.Location = new Point(i++ * 50, 567);
                }
            }
            else if (player == 2)
            {
                if (PlayerTurnCount == 0)
                {
                    Pbplayer2.Visible = false;
                    Pbplayer1.Visible = true;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Green;
                    LblPlayersTurn.Text = Player1Name+" Turn";
                    PlayerTurnCount=1;
                    TbDice.ForeColor = System.Drawing.Color.Navy;
                }
                else
                {
                    Pbplayer1.Visible = false;
                    Pbplayer2.Visible = true;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Navy;
                    LblPlayersTurn.Text = Player2Name+" Turn";
                    PlayerTurnCount = 0;
                    TbDice.ForeColor = System.Drawing.Color.Green;
                }
            }
            else if (player==3)
            {
                if (chance1 == 2)
                {
                    Pbplayer1.Visible = true;
                    Pbplayer2.Visible = false;
                    PbPlayer3.Visible = false;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Green;
                    LblPlayersTurn.Text = Player1Name+" Turn";
                    PlayerTurnCount=2;
                    TbDice.ForeColor = System.Drawing.Color.Purple;
                    chance1 = 0;
                }
                else if (chance1 == 0)
                {
                    Pbplayer1.Visible = false;
                    Pbplayer2.Visible = true;
                    PbPlayer3.Visible = false;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Navy;
                    LblPlayersTurn.Text = Player2Name+" Turn";
                    PlayerTurnCount = 0;
                    chance1 = 1;
                    TbDice.ForeColor = System.Drawing.Color.Green; 
                }
                else if (chance1==1)
                {
                    Pbplayer1.Visible = false;
                    Pbplayer2.Visible = false;
                    PbPlayer3.Visible = true;
                    LblPlayersTurn.ForeColor = System.Drawing.Color.Purple;
                    LblPlayersTurn.Text = Player3Name+" Turn";
                    PlayerTurnCount = 1;
                    chance1 = 2;
                    TbDice.ForeColor = System.Drawing.Color.Navy; 
                }
            }
            Random rnd = new Random();
            var DiceValue = rnd.Next(1, 7);
            TbDice.Text = Convert.ToString(DiceValue);
            GridPosition(DiceValue, PlayerTurnCount, player);
            SerpantsLeft(DiceValue,PlayerTurnCount,player);
            LaddersLeft(DiceValue, PlayerTurnCount, player);
            if (player == 1 && go == 0)
            {
                funtimer();
                go = 1;
            }
         }
        public void funtimer()
        {
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = (3000);              
            timer.Enabled = true;
            timer.Start();
            temp = 0;
        }
        public void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            if (temp == 0)
            {
                BtDice_Click(null, null);
                temp = 1;
            }
        }
        public void LaddersLeft(int Dice, int PlayerTurnCount, int Player)
        {
            if (Dice == 0)
            {
                LblLaddersLeftP1.Text = "5";
                LblLaddersLeftP2.Text = "5";
                LblLaddersLeftP3.Text = "5";
            }
            if (PlayerTurnCount == 0)
            {
                if (grid1 < 5)
                    LblLaddersLeftP1.Text = "5";
                else if (grid1 > 5 && grid1 < 18)
                    LblLaddersLeftP1.Text = "4";
                else if (grid1 > 18 && grid1 < 36)
                    LblLaddersLeftP1.Text = "3";
                else if (grid1 >36 && grid1 < 51)
                    LblLaddersLeftP1.Text = "3";
                else if (grid1 > 51 && grid1 < 66)
                    LblLaddersLeftP1.Text = "1";
                else if (grid1 > 66)
                    LblLaddersLeftP1.Text = "0";
            }
            if (PlayerTurnCount == 1)
            {
                if (grid2 < 5)
                    LblLaddersLeftP2.Text = "5";
                else if (grid2 > 5 && grid2 < 18)
                    LblLaddersLeftP2.Text = "4";
                else if (grid2 > 18 && grid2 < 36)
                    LblLaddersLeftP2.Text = "3";
                else if (grid2 > 36 && grid2 < 51)
                    LblLaddersLeftP2.Text = "3";
                else if (grid2 > 51 && grid2 < 66)
                    LblLaddersLeftP2.Text = "1";
                else if (grid2 > 66)
                    LblLaddersLeftP2.Text = "0";
            }
            if (PlayerTurnCount == 2)
            {
                if (grid3 < 5)
                    LblLaddersLeftP3.Text = "5";
                else if (grid3 > 5 && grid3 < 18)
                    LblLaddersLeftP3.Text = "4";
                else if (grid3 > 18 && grid3 < 36)
                    LblLaddersLeftP3.Text = "3";
                else if (grid3 > 36 && grid3 < 51)
                    LblLaddersLeftP3.Text = "3";
                else if (grid3 > 51 && grid3 < 66)
                    LblLaddersLeftP3.Text = "1";
                else if (grid3 > 66)
                    LblLaddersLeftP3.Text = "0";
            }
        }
        public void SerpantsLeft(int Dice,int PlayerTurnCount,int Player)
        {
            if (Dice == 0)
            {
                LblSerpentsLeftP1.Text = "6";
                LblSerpentsLeftP2.Text = "6";
                LblSerpentsLeftP3.Text = "6";
            }
            if (PlayerTurnCount == 0)
            {
                if (grid1 < 28)
                    LblSerpentsLeftP1.Text = "6";
                else if (grid1 > 28 && grid1 <= 45)
                    LblSerpentsLeftP1.Text = "5";
                else if (grid1 > 45 && grid1 <= 54)
                    LblSerpentsLeftP1.Text = "4";
                else if (grid1 > 54 && grid1 <= 73)
                    LblSerpentsLeftP1.Text = "3";
                else if (grid1 > 73 && grid1 <= 93)
                    LblSerpentsLeftP1.Text = "2";
                else if (grid1 > 93&&grid1<99)
                    LblSerpentsLeftP1.Text = "1";
            }
            else if (PlayerTurnCount == 1)
            {
                if (grid2 < 28)
                    LblSerpentsLeftP2.Text = "6";
                else if (grid2 > 28 && grid2 <= 45)
                    LblSerpentsLeftP2.Text = "5";
                else if (grid2 > 45 && grid2 <= 54)
                    LblSerpentsLeftP2.Text = "4";
                else if (grid2 > 54 && grid2 <= 73)
                    LblSerpentsLeftP2.Text = "3";
                else if (grid2 > 73 && grid2 <= 93)
                    LblSerpentsLeftP2.Text = "2";
                else if (grid2 > 93&&grid2<99)
                    LblSerpentsLeftP2.Text = "1";
            }
            if (PlayerTurnCount == 2)
            {
                if (grid3 < 28)
                    LblSerpentsLeftP3.Text = "6";
                else if (grid3 > 28 && grid3 <= 45)
                    LblSerpentsLeftP3.Text = "5";
                else if (grid3 > 45 && grid3 <= 54)
                    LblSerpentsLeftP3.Text = "4";
                else if (grid3 > 54 && grid3 <= 73)
                    LblSerpentsLeftP3.Text = "3";
                else if (grid3 > 73 && grid3 <= 93)
                    LblSerpentsLeftP3.Text = "2";
                else if (grid3 > 93 && grid3 < 99)
                    LblSerpentsLeftP3.Text = "1";
            }
        }
        public void GridPosition(int Dice,int PlayerTurnCount,int player)
        {
            if (Dice == 0)
            {
                LblGridPositionPlayer1.Text = "0";
                LblGridPositionPlayer2.Text = "0";
                LblGridPositionPlayer3.Text = "0";
            }
            if (PlayerTurnCount == 0)
            {
                grid1 = grid1 + Dice;
                if (grid1 <= 100)
                {
                    switch (grid1)
                    {
                        case 5: grid1 = 14; break;
                        case 18: grid1 = 41; break;
                        case 36: grid1 = 67; break;
                        case 51: grid1 = 90; break;
                        case 66: grid1 = 97; break;
                        case 45: grid1 = 38; break;
                        case 99: grid1 = 56; break;
                        case 54: grid1 = 26; break;
                        case 73: grid1 = 50; break;
                        case 28: grid1 = 10; break;
                        case 93: grid1 = 75; break;
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Move", "Warning");
                    grid1 = grid1 - Dice;
                }
                LblGridPositionPlayer1.Text = Convert.ToString(grid1);
                PlayerCoinLocation(grid1,PlayerTurnCount);
                if (grid1 == 100)
                {
                    LblSerpentsLeftP1.Text = "0";
                    Form2 win = new Form2(Player1Name);
                    win.ShowDialog();
                    groupBox2.Visible = true;
               }
            }
            else if (PlayerTurnCount == 1)
            {
                grid2 = grid2 + Dice;
                if (grid2 <= 100)
                {
                    switch (grid2)
                    {
                        case 5: grid2 = 14; break;
                        case 18: grid2 = 41; break;
                        case 36: grid2 = 67; break;
                        case 51: grid2 = 90; break;
                        case 66: grid2 = 97; break;
                        case 45: grid2 = 38; break;
                        case 99: grid2 = 56; break;
                        case 54: grid2 = 26; break;
                        case 73: grid2 = 50; break;
                        case 28: grid2 = 10; break;
                        case 93: grid2 = 75; break;
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Move", "Warning");
                    grid2 = grid2 - Dice;
                }
                LblGridPositionPlayer2.Text = Convert.ToString(grid2);
                PlayerCoinLocation(grid2, PlayerTurnCount);
                if (grid2 == 100)
                {
                    LblSerpentsLeftP2.Text = "0";
                    if (player == 1)
                    {
                        
                        Form2 win = new Form2("Computer");
                        win.ShowDialog();
                        groupBox2.Visible = true;
                    }
                    else
                    {
                        Form2 win = new Form2(Player2Name);
                        win.ShowDialog();
                        groupBox2.Visible = true;
                    }
                   // MessageBox.Show(Player2Name+" Won", "Congratulations");
                }
            }
            else if (PlayerTurnCount == 2)
            {
                grid3 = grid3 + Dice;
                if (grid3 <= 100)
                {
                    switch (grid3)
                    {
                        case 5: grid3 = 14; break;
                        case 18: grid3 = 41; break;
                        case 36: grid3 = 67; break;
                        case 51: grid3 = 90; break;
                        case 66: grid3 = 97; break;
                        case 45: grid3 = 38; break;
                        case 99: grid3 = 56; break;
                        case 54: grid3 = 26; break;
                        case 73: grid3 = 50; break;
                        case 28: grid3 = 10; break;
                        case 93: grid3 = 75; break;
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Move", "Warning");
                    grid3 = grid3 - Dice;
                }
                LblGridPositionPlayer3.Text = Convert.ToString(grid3);
                PlayerCoinLocation(grid3, PlayerTurnCount);
                if (grid3 == 100)
                {
                    LblSerpentsLeftP3.Text = "0";
                    Form2 win = new Form2(Player3Name);
                    win.ShowDialog();
                    groupBox2.Visible = true;
               }
            }
        }
        private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
             SnakeBoard_Load(null,null);
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
        }
        private void MscriptFileUndo_Click(object sender, EventArgs e)
        {
        }
        private void filesToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }
        private void howToPlayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string helpIns = "Worldwide classical Game Snake and Ladder is an ancient Indian game  orginated in INDIA.The \"Snakes\" and the \"Ladders are present on the board. The game is played between two or more players on a gameboard having numbered, gridded squares.According to die rolls the player helped and hindered by the ladders and snakes.The player who reach the destination will be consider as winner. The aim of the Snake Board PC game is to provide better feelings than you play the same on board with rolling dice\n\nHow to Play\n\nRoll the dice by clicking the Dice button on the bottom right based on the value of dice the position of the player coin will move from one place to other the winner will be the player who reach the destination first";
            string help = "Help"; 
            MessageBox.Show(helpIns, help);
        }
        private void viewMoreGamesToolStripMenuItem_Click(object sender, EventArgs e)
        {
           System.Diagnostics.Process.Start("http://www.xbox.com/en-in/Live/PC");
        }
        private void SnakeBoard_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (formclosingcount == 0)
            {
                string MbInstructuionQuit = "Do you want to Quit this Game";
                string Mbquit = "Quit Window";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult result = MessageBox.Show(MbInstructuionQuit, Mbquit, buttons);
                if (result == DialogResult.Yes)
                {
                    threadtry(1);
                    Environment.Exit(0);
                }
                else
                {
                  //  threadtry(0);
                    e.Cancel = true;
                }
           }
        }
        private void pictureBox5_Click(object sender, EventArgs e)
        {

        }
        private void Pbtrail_Click(object sender, EventArgs e)
        {

        }
        private void pictureBox92_Click(object sender, EventArgs e)
        {

        }
        private void pictureBox201_Click(object sender, EventArgs e)
        {

        }
        private void pictureBox90_Click(object sender, EventArgs e)
        {

        }
        private void pictureBox266_Click(object sender, EventArgs e)
        {

        }
        private void pictureBox197_Click(object sender, EventArgs e)
        {

        }
        private void GbPlayer3_Enter(object sender, EventArgs e)
        {

        }
        private void GbPlayer1_Enter(object sender, EventArgs e)
        {

        }
        private void GbPlayer2_Enter(object sender, EventArgs e)
        {
            
        }
        private void BtPlayerNameOk_Click(object sender, EventArgs e)
        {
                playernamecount = 1;
                lblPlayerNameNotification.Visible = true;
                Player1Name = Convert.ToString(TbPlayer1Name.Text);
                Player2Name = Convert.ToString(TbPlayer2Name.Text);
                Player3Name = Convert.ToString(TbPlayer3Name.Text);
                SnakeBoard_Load(null, null);
                if (player == 1)
                {
                    if (Player1Name.Length == 0)
                    {
                        lblPlayerNameNotification.Text = "Player name Should not be blank";
                        LblPlayernameNotification2.Text = "(type eg:Miss J)";
                    }
                    else
                        groupBox2.Visible = false;
                }
                else if (player == 2)
                {
                    if (Player1Name.Length == 0 || Player2Name.Length == 0)
                    {
                        lblPlayerNameNotification.Text = "Player name Should not be blank";
                        LblPlayernameNotification2.Text = "(type eg:Miss J)";
                    }
                    else
                        groupBox2.Visible = false;
                }
                else if (player == 3)
                {
                    if (Player1Name.Length == 0 || Player2Name.Length == 0 || Player3Name.Length == 0)
                    {
                        lblPlayerNameNotification.Text = "Player name Should not be blank";
                        LblPlayernameNotification2.Text = "(type eg:Miss J)";
                    }
                    else
                        groupBox2.Visible = false;
                }
        }
        private void BtPlayAgainstWhom_Click(object sender, EventArgs e)
        {
            lblPlayerNameNotification.Visible = false;            
                if (comboBox1.Text == "Against Computer")
                {
                    PlayerName(true, true, false, false, false, false,true);
                    Playertick(true, false, false);
                    player = 1;
                    Pblogo.Visible = true;
                }
                else if (comboBox1.Text == "Against Player")
                {
                    PlayerName(true, true, true, true, false, false,true);
                    Playertick(false, true, false);
                    player = 2;
                    Pblogo.Visible = true;
                }
                else if (comboBox1.Text == "Against Multiple Player")
                {
                    PlayerName(true, true, true, true, true, true,true);
                    Playertick(false, false, true);
                    player = 3;
                    Pblogo.Visible = false;
                }
                else
                {
                    lblPlayerNameNotification.Visible = true;
                    lblPlayerNameNotification.Text = "Select your option from Drop down";
                }
        }
        private void pictureBox7_Click(object sender, EventArgs e)
        {
          
        }
    }
}
